package com.qfedu.stussm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.stussm.dao.JwDeptDao;
import com.qfedu.stussm.dao.JxDeptDao;
import com.qfedu.stussm.dto.JxDeptDto;
import com.qfedu.stussm.entity.JwDept;
import com.qfedu.stussm.entity.JxDept;
import com.qfedu.stussm.service.intf.JwDeptService;
import com.qfedu.stussm.service.intf.JxDeptService;
import com.qfedu.stussm.vo.DeptR;
import com.qfedu.stussm.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service

public class JxDeptServiceImpl implements JxDeptService {
    @Autowired
    private JxDeptDao jxDeptDao;
    @Override
    public DeptR insert(JxDept jxDept) {
        System.out.println(jxDept);
        if(jxDeptDao.insert(jxDept)>0){
            return DeptR.ok();
        }else{
            return DeptR.fail();
        }
    }
    @Override
    public PageBeanVo select(String jxdept_name,int page, int limit) {
        PageHelper.startPage(page,limit);
        if(jxdept_name!=null && jxdept_name.length()>0){
            jxdept_name="%"+jxdept_name+"%";
            System.out.println(jxdept_name);
        }else{
            jxdept_name=null;
        }
        PageInfo<JxDeptDto> pageInfo = new PageInfo<>(jxDeptDao.select(jxdept_name));
        return new PageBeanVo(pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public DeptR del(Integer id) {
        if(jxDeptDao.del(id)>0){
            return DeptR.ok();
        }else{
            return  DeptR.fail();
        }
    }

    @Override
    public DeptR update(JxDept jxDept) {
        if(jxDeptDao.update(jxDept)>0){
            return DeptR.ok();
        }else{
            return  DeptR.fail();
        }
    }
    @Override
    public DeptR dele(Integer[] ids) {
        if(jxDeptDao.dele(ids)>0){
            return DeptR.ok();
        }else{
            return DeptR.fail();
        }
    }
}
